package cn.itcast.Proxy;

import java.util.ArrayList;

/**
 * @Author : 叶荻风
 * @create : 2024/8/6 19:24
 */
public class Test {

    public static void testStaticProxy(String message){
        SmsService smsService = new SmsServiceImpl();
        SmsServiceProxy proxy = new SmsServiceProxy(smsService);
        String send = proxy.send(message);
        System.out.println("send message: "+send);
    }

    public static void testDynamicProxy(String message){

        SmsService smsService = new SmsServiceImpl();
        LogInvocationHandler logInvocationHandler = new LogInvocationHandler(smsService);

        SmsService proxy = (SmsService) logInvocationHandler.getProxy(Test.class.getClassLoader(),
                new Class[]{SmsService.class});
        String send = proxy.send(message);
        System.out.println("send message: "+send);
    }

    public static void testCGlibProxy(String message) throws InstantiationException, IllegalAccessException {
        AliSmsService proxy = (AliSmsService)CGlibProxy.getProxy(AliSmsService.class);
        proxy.send(message);

    }


    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        //testStaticProxy("message");
        //testDynamicProxy("message");
        testCGlibProxy("java");

    }
}
